<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


require_once(dirname(dirname(__FILE__)) . '/appwap.php');

$lat=$_GET['lat'];
$lon=$_GET['lon'];


if($lat && $lon){
	Session::Set('mylat', $lat);
	Session::Set('mylng', $lon);
	$url="http://api.map.baidu.com/geocoder?location=".$lat.",".$lon."&output=json&key=28bcdd84fae25699606ffad27f8da77b";
	$data= json_decode(file_get_contents($url));
	$cityName=strval($data->result->addressComponent->city);
}

/*if($city&&option_yes('rewritecity')){
	redirect(WEB_ROOT."/{$city['ename']}");
}*/


if($cityName){
	$cn=str_replace("市","",$cityName);
	
	
	$city=DB::GetTableRow('category', array(
					'zone'=>'city',
					'display'=>'Y',
					"(name like '%{$cn}%')",
				));
	if($city)
		cookie_city($city);
}

$request_uri = 'index';

$daytime = time();

/*wap首页头部轮换*/
$banner_cond = array(
				'display'=>'Y',
				"begin_time <= {$daytime}",
				"end_time > {$daytime}",
				'position' => 'banner',
			);
$banners = DB::LimitQuery('banner', array(
				'condition' => $banner_cond,
				'order' => 'ORDER BY sort_order DESC, id DESC',
			));
/*wap中间第一排*/
$wapone_cond = array(
				'display'=>'Y',
				"begin_time <= {$daytime}",
				"end_time > {$daytime}",
				'position' => 'wapone',
			);
$wapones = DB::LimitQuery('banner', array(
				'condition' => $wapone_cond,
				'order' => 'ORDER BY sort_order DESC, id DESC',
			));
/*wap中间第二排*/
$waptwo_cond = array(
				'display'=>'Y',
				"begin_time <= {$daytime}",
				"end_time > {$daytime}",
				'position' => 'waptwo',
			);
$waptwos = DB::LimitQuery('banner', array(
				'condition' => $waptwo_cond,
				'order' => 'ORDER BY sort_order DESC, id DESC',
			));
		

$conditions = array( 
		'team_type' => 'seconds',
		"begin_time <  {$daytime}",
		//'city_id' => $city['id'],
		"end_time > {$daytime}",
		"(city_ids like '%@{$city['id']}@%') or (city_ids = '' and city_id ={$city['id']})",
		);
$condition = array( 
		'team_type' => 'normal',
		"begin_time <  {$daytime}",
		"end_time > {$daytime}",
		//'city_id' => $city['id'],
		"(city_ids like '%@{$city['id']}@%') or (city_ids = '' and city_id ={$city['id']})"
		);

if(!empty($_GET['city'])){
  $city_id = abs(intval($_GET['city']));
  $city = Table::Fetch('category', $city_id);  
  cookie_city($city);
}else{
  $city_id = abs(intval($city['id']));
}		
		
/*echo $city_id; 判断城市*/
$condition['city_id'] = $city_id;
$conditions['city_id'] = $city_id;



 /*分类查询*/
$category = DB::LimitQuery('category',array(
	'condition'=>array(
		'zone'=>'group',
		'is_hot' =>'Y',
		'display'=>'Y',
	),
	'order' => 'ORDER BY sort_order DESC, id DESC',
	'size' => 15,				
));
			
		
$size = $_GET['size'];	

$size = !empty($size) ? $size : 50;	
$counts = Table::Count('team', $conditions);
list($pagesize, $offset, $pagestrings) = pagestring($counts, $size, true);
$teams = DB::LimitQuery('team', array(
			'condition' => $conditions,
			'order' => 'ORDER BY begin_time DESC, id DESC',
			'size' => $pagesize,
			'offset' => $offset,
			));
$count = Table::Count('team', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, $size, true);
$teamss = DB::LimitQuery('team', array(
			'condition' => $condition,
			'order' => 'ORDER BY begin_time DESC, id DESC',
			'size' => 30,
			'offset' => $offset,
			));
			

$pagetitle = $INI['system']['abbreviation'];


include template('m_index');
